package com.example.tellwin.mine.act;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.example.tellwin.MainApplication;
import com.example.tellwin.R;
import com.example.tellwin.base.CpBaseActivty;
import com.example.tellwin.base.DaggerRxComponent;
import com.example.tellwin.common.Common;
import com.example.tellwin.mine.bean.UserContentBean;
import com.example.tellwin.mine.contract.ApplyResultContract;
import com.example.tellwin.mine.presenter.ApplyResultPresenter;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ApplyResultActivity extends CpBaseActivty implements ApplyResultContract.View {

    @BindView(R.id.state_iv)
    ImageView stateIv;
    @BindView(R.id.applying_tv)
    TextView applyingTv;
    @BindView(R.id.fail_cause_tv)
    TextView failCauseTv;
    @BindView(R.id.commit_btn)
    TextView commitBtn;
    @BindView(R.id.fail_ll)
    LinearLayout failLl;

    String Audits;
    UserContentBean userContentBean;

    @Inject
    ApplyResultPresenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_apply_result);
        ButterKnife.bind(this);
        initViews();
        initEvents();
        initDatas();
    }

    @Override
    protected void initViews() {
        DaggerRxComponent.builder()
                .baseAppComponent(MainApplication.getAppComponent())
                .build()
                .inject(this);
        mPresenter.attachView(this);
    }

    @Override
    protected void initEvents() {

    }

    @Override
    protected void initDatas() {
        setTitle(R.string.apply_detial);
        Audits = getIntent().getStringExtra(Common.AUDITS);
        userContentBean = (UserContentBean) getIntent().getSerializableExtra(Common.USERINFO);
        if (TextUtils.isEmpty(Audits)) {
            finish();
        }

        if (Audits.equals(Common.AUDITS_WAIT)) {//待审核
            stateIv.setImageResource(R.mipmap.pic_wait_audit);
            applyingTv.setVisibility(View.VISIBLE);
            failLl.setVisibility(View.GONE);
        } else if (Audits.equals(Common.AUDITS_SUCCESS)) {//审核通过

        } else if (Audits.equals(Common.AUDITS_FAIL)) {//审核拒绝
            mPresenter.getApplyFailReason();
            stateIv.setImageResource(R.mipmap.pic_failure_audit);
            applyingTv.setVisibility(View.GONE);
            failLl.setVisibility(View.VISIBLE);
        }
    }

    @OnClick(R.id.commit_btn)
    public void onViewClicked() {
        Intent intent = new Intent(this, MineDetailActivity.class);
        intent.putExtra(Common.USERINFO, userContentBean);
        intent.putExtra(Common.TYPE, Common.ApplyAnswer);
        startActivityForResult(intent, Common.MineDetailRequestCode);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == Common.MineDetailRequestCode && resultCode == Common.MineDetailResultCode) {
            setResult(Common.MineDetailResultCode);
            finish();
        }
    }

    @Override
    public void applyFailReason(String reason) {
        failCauseTv.setText(reason);
    }
}
